package com.lucker.common.util;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * Created by PC on 2019/7/17.
 */

public class MissDataUtilNew {

    //misscode_list表里循环出来caiId对应的missTypeId和num和开奖号码和当前遗漏
    public static boolean isNumsBingGo(int missTypeId, Set<Integer> firstNums,Set<Integer> secondNums,Set<Integer> awardNums){
        if(missTypeId==8){// 前一直选
            /*if(firstNums.get(0)==awardNums.get(0)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }*/
        }else if(missTypeId==9){// 前二直选
            /*if(firstNums.get(0)==awardNums.get(0)&&firstNums.get(1)==awardNums.get(1)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }*/
        }else if(missTypeId==11){// 前三直选
            /*if(firstNums.get(0)==awardNums.get(0)&&firstNums.get(1)==awardNums.get(1)&&firstNums.get(2)==awardNums.get(2)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }*/
        }else if(missTypeId>=13&&missTypeId<=15){// 任二 单式三码四码
            if(isMissValueReset(firstNums,awardNums,2)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }

        }else if(missTypeId>=16&&missTypeId<=18){// 任二的胆拖玩法
            if(isDanTuoMissValueReset(firstNums,secondNums,awardNums,2)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId>=19&&missTypeId<=21){// 任三多码
            if(isMissValueReset(firstNums,awardNums,3)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }

        }else if(missTypeId>=22&&missTypeId<=32){// 任三的胆拖玩法
            if(isDanTuoMissValueReset(firstNums,secondNums,awardNums,3)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId>=34&&missTypeId<=37){// 任四多码
            if(isMissValueReset(firstNums,awardNums,4)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }

        }else if(missTypeId>=38&&missTypeId<=55){// 任四的胆拖玩法
            if(isDanTuoMissValueReset(firstNums,secondNums,awardNums,4)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId == 56){// 任五单式
            if(awardNums.containsAll(firstNums)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId>=57&&missTypeId<=80){// 任五的胆拖玩法
            if(isDanTuoMissValueReset(firstNums,secondNums,awardNums,5)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId==81){//任六单式
            if(firstNums.containsAll(awardNums)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId>=83&&missTypeId<=110) {// 任六的胆拖玩法
            if(isDanTuoBigMissValueReset(firstNums,secondNums,awardNums,6)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId==111){//任七单式
            if(firstNums.containsAll(awardNums)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId>=112&&missTypeId<=125) {// 任七的胆拖玩法
            if(isDanTuoBigMissValueReset(firstNums,secondNums,awardNums,7)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId==126){//任八单式
            if(firstNums.containsAll(awardNums)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId>=127&&missTypeId<=135) {// 任七的胆拖玩法
            if(isDanTuoBigMissValueReset(firstNums,secondNums,awardNums,8)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId>=136&&missTypeId<=146){//前二组
            /*ArrayList<Integer> pre2List = new ArrayList<>();
            pre2List.add(awardNums.get(0));
            pre2List.add(awardNums.get(1));
            if (missTypeId==136){
                if(firstNums.containsAll(pre2List)){
                    //该条数据当前遗漏置0
                    return true;
                }else {
                    //该条数据当前遗漏+1
                    return false;
                }
            }else {
                if(isDanTuoMissValueReset(firstNums,secondNums,pre2List,2)){
                    //该条数据当前遗漏置0
                    return true;
                }else {
                    //该条数据当前遗漏+1
                    return false;
                }
            }*/

        }else if(missTypeId>=147&&missTypeId<=163){//前三组
            /*ArrayList<Integer> pre3List = new ArrayList<>();
            pre3List.add(awardNums.get(0));
            pre3List.add(awardNums.get(1));
            pre3List.add(awardNums.get(2));
            if (missTypeId==147){
                if(firstNums.containsAll(pre3List)){
                    //该条数据当前遗漏置0
                    return true;
                }else {
                    //该条数据当前遗漏+1
                    return false;
                }
            }else {
                if(isDanTuoMissValueReset(firstNums,secondNums,pre3List,3)){
                    //该条数据当前遗漏置0
                    return true;
                }else {
                    //该条数据当前遗漏+1
                    return false;
                }
            }*/

        }
        return false;
        //完成之后把数据库该条数据更新掉（包括最大遗漏和近10次遗漏）
    }

    //misscode_list表里循环出来caiId对应的missTypeId和num和开奖号码和当前遗漏
    public static int calculateCurrentMissValue(int missTypeId, Set<Integer> firstNums,Set<Integer> secondNums,Set<Integer> awardNums,int currentMissValue){
        if(missTypeId==8){// 前一直选
            /*if(firstNums.get(0)==awardNums.get(0)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }*/
        }else if(missTypeId==9){// 前二直选
            /*if(firstNums.get(0)==awardNums.get(0)&&firstNums.get(1)==awardNums.get(1)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }*/
        }else if(missTypeId==11){// 前三直选
           /* if(firstNums.get(0)==awardNums.get(0)&&firstNums.get(1)==awardNums.get(1)&&firstNums.get(2)==awardNums.get(2)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }*/
        }else if(missTypeId>=13&&missTypeId<=15){// 任二 单式三码四码
            if(isMissValueReset(firstNums,awardNums,2)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }

        }else if(missTypeId>=16&&missTypeId<=18){// 任二的胆拖玩法
            if(isDanTuoMissValueReset(firstNums,secondNums,awardNums,2)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId>=19&&missTypeId<=21){// 任三多码
            if(isMissValueReset(firstNums,awardNums,3)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }

        }else if(missTypeId>=22&&missTypeId<=32){// 任三的胆拖玩法
            if(isDanTuoMissValueReset(firstNums,secondNums,awardNums,3)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId>=34&&missTypeId<=37){// 任四多码
            if(isMissValueReset(firstNums,awardNums,4)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }

        }else if(missTypeId>=38&&missTypeId<=55){// 任四的胆拖玩法
            if(isDanTuoMissValueReset(firstNums,secondNums,awardNums,4)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId == 56){// 任五单式
            if(awardNums.containsAll(firstNums)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId>=57&&missTypeId<=80){// 任五的胆拖玩法
            if(isDanTuoMissValueReset(firstNums,secondNums,awardNums,5)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId==81){//任六单式
            if(firstNums.containsAll(awardNums)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId>=83&&missTypeId<=110) {// 任六的胆拖玩法
            if(isDanTuoBigMissValueReset(firstNums,secondNums,awardNums,6)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId==111){//任七单式
            if(firstNums.containsAll(awardNums)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId>=112&&missTypeId<=125) {// 任七的胆拖玩法
            if(isDanTuoBigMissValueReset(firstNums,secondNums,awardNums,7)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId==126){//任八单式
            if(firstNums.containsAll(awardNums)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId>=127&&missTypeId<=135) {// 任七的胆拖玩法
            if(isDanTuoBigMissValueReset(firstNums,secondNums,awardNums,8)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId>=136&&missTypeId<=146){//前二组
            /*ArrayList<Integer> pre2List = new ArrayList<>();
            pre2List.add(awardNums.get(0));
            pre2List.add(awardNums.get(1));
            if (missTypeId==136){
                if(firstNums.containsAll(pre2List)){
                    //该条数据当前遗漏置0
                    currentMissValue = 0;
                }else {
                    //该条数据当前遗漏+1
                    currentMissValue = currentMissValue+1;
                }
            }else {
                if(isDanTuoMissValueReset(firstNums,secondNums,pre2List,2)){
                    //该条数据当前遗漏置0
                    currentMissValue = 0;
                }else {
                    //该条数据当前遗漏+1
                    currentMissValue = currentMissValue+1;
                }
            }*/

        }else if(missTypeId>=147&&missTypeId<=163){//前三组
            /*ArrayList<Integer> pre3List = new ArrayList<>();
            pre3List.add(awardNums.get(0));
            pre3List.add(awardNums.get(1));
            pre3List.add(awardNums.get(2));
            if (missTypeId==147){
                if(firstNums.containsAll(pre3List)){
                    //该条数据当前遗漏置0
                    currentMissValue = 0;
                }else {
                    //该条数据当前遗漏+1
                    currentMissValue = currentMissValue+1;
                }
            }else {
                if(isDanTuoMissValueReset(firstNums,secondNums,pre3List,3)){
                    //该条数据当前遗漏置0
                    currentMissValue = 0;
                }else {
                    //该条数据当前遗漏+1
                    currentMissValue = currentMissValue+1;
                }
            }*/

        }
        return currentMissValue;
        //完成之后把数据库该条数据更新掉（包括最大遗漏和近10次遗漏）
    }

    //任选多码玩法是否中奖 count是满足中奖条件的号码个数
    public static boolean isMissValueReset(Set<Integer> firstNumsSet,Set<Integer> awardNumsSet, int count){
        int realCount = 0;
        Iterator it = firstNumsSet.iterator();
        while (it.hasNext()){
            if(awardNumsSet.contains(it.next())){
                realCount++;
                if(realCount>=count){
                    return true;
                }
            }
        }
        return false;
    }

    //任五以及任五以下任选胆拖玩法是否中奖 count是满足中奖条件的号码个数
    public static boolean isDanTuoMissValueReset(Set<Integer> firstNumsSet,Set<Integer> secondNumsSet,Set<Integer> awardNumsSet, int count){

        int realCount = 0;
        int firstSize = firstNumsSet.size();
        if(awardNumsSet.containsAll(firstNumsSet)){
            Iterator it = secondNumsSet.iterator();
            while (it.hasNext()){
                if(awardNumsSet.contains(it.next())){
                    realCount++;
                    if(realCount>=count-firstSize){
                        return true;
                    }
                }
            }
            return false;
        }else {
            return false;
        }
    }

    //任六以及任六以上任选胆拖玩法是否中奖 count是玩法单注号码个数
    public static boolean isDanTuoBigMissValueReset(Set<Integer> firstNumsSet,Set<Integer> secondNumsSet,Set<Integer> awardNumsSet, int count){

        int realCount = 0;
        int firstSize = firstNumsSet.size();
        if(awardNumsSet.containsAll(firstNumsSet)){
            Iterator it = secondNumsSet.iterator();
            while (it.hasNext()){
                if(awardNumsSet.contains(it.next())){
                    realCount++;
                    if(realCount>=5-firstSize){
                        return true;
                    }
                }
            }
            return false;
        }else {
            int firstRealCount=0;
            Iterator it = firstNumsSet.iterator();
            while (it.hasNext()){
                if(awardNumsSet.contains(it.next())){
                    firstRealCount++;
                }
            }
            if(count-firstSize+firstRealCount>=5){
                Iterator it_sec = secondNumsSet.iterator();
                while (it_sec.hasNext()){
                    if(awardNumsSet.contains(it_sec.next())){
                        realCount++;
                        if(realCount>=5-firstRealCount){
                            return true;
                        }
                    }
                }
                return false;
            }else {
                return false;
            }
        }
    }


    /*public static void testString(){
        long time1 = System.currentTimeMillis();
        String sb1 = "";
        for (int i=0;i<12000;i++){
            String temp = 68000 + "|" + 131 + "|" + "2,3,4,5" + "|" +   "6,7,8,9,10" + "|" + 2 + "|" + 15 + "|" + 35;
            sb1 = sb1 + temp+",";
        }
        Log.e("timesssss","1-------"+(System.currentTimeMillis()-time1));

        long time2 = System.currentTimeMillis();
        StringBuilder sb2 = new StringBuilder();
        for (int i=0;i<12000;i++){
            String temp = 68000 + "|" + 131 + "|" + "2,3,4,5" + "|" +   "6,7,8,9,10" + "|" + 2 + "|" + 15 + "|" + 35;
            sb2.append(temp).append(",");
        }
        Log.e("timesssss","2-------"+(System.currentTimeMillis()-time2));

        long time3 = System.currentTimeMillis();
        StringBuilder sb3 = new StringBuilder();
        for (int i=0;i<12000;i++){
            StringBuilder temp = new StringBuilder(68000).append("|").append(131).append("|").append("2,3,4,5").append("|").append("6,7,8,9,10").append("|").append(2).append("|").append(15).append("|").append(35);
            sb3.append(temp).append(",");
        }
        Log.e("timesssss","3-------"+(System.currentTimeMillis()-time3));
    }*/
}
